import json
import os

class Earthquake:
    """地震数据类"""

    def __init__(self, filename) -> None:
        # 地震数据, 名称, 经度, 维度
        self.mags, self.titles, self.lons, self.lats = [], [], [], []
        # 文件路径
        self.current_url = os.getcwd()
        # 文件名称
        self.earthquake_title = ''
        # 加载读取数据
        self._load(filename)

    def _load(self, filename):
        """加载读取数据"""

        filename = f'{self.current_url}/json_sif/file/{filename}'
        with open(filename) as file:
            readable_eq_data = json.load(file)

        self.earthquake_title = readable_eq_data['metadata']['title']
        all_eq_dicts = readable_eq_data['features']
        for dict in all_eq_dicts:
            self.titles.append(dict['properties']['title'])
            self.mags.append(dict['properties']['mag'])
            self.lons.append(dict['geometry']['coordinates'][0])
            self.lats.append(dict['geometry']['coordinates'][1])